//
//  STNavigationController.m
//  STTools
//
//  Created by stoneobs on 16/10/9.
//  Copyright © 2016年 stoneobs. All rights reserved.
//

#import "STNavigationController.h"
#import "STMusic-swift.h"
@interface STNavigationController ()

@end

@implementation STNavigationController

-(instancetype)initWithRootViewController:(UIViewController *)rootViewController
{
    
    if (self = [super initWithRootViewController:rootViewController]) {
        self.interactivePopGestureRecognizer.delegate=(id)self;
        self.view.backgroundColor = [UIColor whiteColor];
        [self.navigationBar setBarTintColor:[UIColor whiteColor]];
        self.navigationBar.backgroundColor = [UIColor whiteColor];
        //title
        [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
        //删除线
        self.delegate = self;
        self.interactivePopGestureRecognizer.delegate = (id)self;
       // [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
        
    }
    return self;
}
-(void)awakeFromNib
{
   
    self.interactivePopGestureRecognizer.delegate=(id)self;
    [self.navigationBar setBarTintColor:[UIColor whiteColor]];
    self.navigationBar.backgroundColor = [UIColor whiteColor];
    //title
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]}];
    //删除黑线,切图不统一，有些隐藏黑线，有些不隐藏，
    //    [[UINavigationBar appearance]  setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    //    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    [super awakeFromNib];
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        //隐藏播放按钮
        [YYDefaultMusicAnimationView sharedInstance].hidden = YES;
        self.hidesBottomBarWhenPushed = YES;
        //设置返回键
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn addTarget:self action:@selector(back)  forControlEvents:UIControlEventTouchUpInside];
        [btn setImage:[UIImage imageNamed:@"STTools.bundle/STImages/nav_back.png"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"STTools.bundle/STImages/nav_back.png"] forState:UIControlStateHighlighted];
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        btn.frame = CGRectMake(0, 0, 44, 44);
        viewController.navigationItem.leftBarButtonItem =  [[UIBarButtonItem alloc] initWithCustomView:btn];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}
- (void)back
{
    [self popViewControllerAnimated:YES];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{

   return  [super popViewControllerAnimated:animated];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count == 1) {
        //显示播放按钮
       // [YYDefaultMusicAnimationView sharedInstance].hidden = NO;
    }
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

    if (self.childViewControllers.count == 1) {
        //显示播放按钮
      //  [YYDefaultMusicAnimationView sharedInstance].hidden = NO;
    }
}
@end
